/*
Copyright 2007 Luke Benstead

This file is part of slMath.

slMath is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

slMath is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser Public License for more details.

You should have received a copy of the GNU Lesser Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef UTILITY_H_INCLUDED
#define UTILITY_H_INCLUDED

#include <cmath>

#ifdef USE_DOUBLE_PRECISION
	typedef double slScalar;
#else
	typedef float slScalar;
#endif

#define SLNULL 0L

const slScalar slPI = 3.14159;
const slScalar slPIOver180 = slPI / 180.0f;
const slScalar slPIUnder180 = 180.0f / slPI;
const slScalar slEpsilon = 64.0 / 1.0;

inline slScalar slCos(slScalar s) {
#ifdef USE_DOUBLE_PRECISION
	return cos(s);
#else
	return cosf(s);
#endif
}

inline slScalar slACos(slScalar s) {
#ifdef USE_DOUBLE_PRECISION
	return acos(s);
#else
	return acosf(s);
#endif
}

inline slScalar slSin(slScalar s) {
#ifdef USE_DOUBLE_PRECISION
	return sin(s);
#else
	return sinf(s);
#endif
}

inline slScalar slAbs(slScalar s) {

	if (s < 0) s *= -1;

	return s;
}

inline slScalar slSqrt(slScalar s) {
#ifdef USE_DOUBLE_PRECISION
	return sqrt(s);
#else
	return sqrtf(s);
#endif
}

inline slScalar slSQR(slScalar s) {
	return s*s;
}


inline slScalar slDegreesToRadians(slScalar degrees) {
	return degrees * slPIOver180;
}

inline slScalar slRadiansToDegrees(slScalar radians) {
	return radians * slPIUnder180;
}

#endif // UTILITY_H_INCLUDED
